home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_6_3.arc / CASE next >
Text File  |  1988-04-05  |  15KB  |  528 lines

  1. Code from "A CASE of the Jumps" by Tom Swan.  No commercial use
  2. of this code without express permission of the author.
  3.  
  4.  
  5. .RR       L----!----!----!----!----!----!----!----!----!---------R
  6. .MT 5
  7. .HM 4
  8. .UJ 0
  9. .PN 1
  10. .OP
  11. .HE   CASE           Copyright (C) 1988 by Tom Swan                 Page-# 
  12. .FO
  13. .LS 2
  14. ááááááááááì
  15.  
  16. ááááááááááSubmitteΣ to║   Programmer'≤ Journa∞ ì
  17.  
  18. ááááááááááDate║           Februar∙ 8¼ 198╕ ì
  19.  
  20. ááááááááááRight≤ offered║ Firs⌠ Seria∞ Right≤ ì
  21.  
  22. ááááááááááNo« oµ words║   170░ ½ │ listing≤ ½ ▒ figure ì
  23.  
  24. ááááááááááAddress║        10╢ Sharonß Drive¼ Litit· P┴ 1754│ ì
  25.  
  26. ááááááááááPhone║          (717⌐ 62╖-191▒ (╣-╡ Easterε time⌐ ì
  27.  
  28. ááááááááááì
  29.  
  30. ááááááááááì
  31.  
  32. ááááááááááì
  33.  
  34. ááááááááááì
  35.  
  36. ááááááááááì
  37.  
  38. ááááááááááì
  39.  
  40. áááááááááá                  ┴ CAS┼ oµ thσ Jump≤ ì
  41.  
  42. ááááááááááì
  43.  
  44. áááááááááá                      b∙ Toφ Swaε ì
  45.  
  46. ááááááááááì
  47.  
  48. ááááááááááì
  49.  
  50. áááááááááá     Turb∩ Pasca∞ 4.0░ cheat≤ wheε i⌠ compile≤ ß CAS┼ ì
  51. ì
  52. áááááááááástatement«  InsteaΣ oµ creatinτ ß jum≡ tablσ oµ CAS┼-ì
  53. ì
  54. áááááááááálabe∞ addresse≤ a≤ yo⌡ migh⌠ expect¼ thσ compile≥ ì
  55. ì
  56. áááááááááágenerate≤ ß serie≤ oµ conditiona∞ jumps«  Thi≤ sleigh⌠ ì
  57. ì
  58. ááááááááááoµ hanΣ turn≤ ß potentiall∙ fas⌠ CAS┼ int∩ ß sluggisΦ ì
  59. ì
  60. ááááááááááserie≤ oµ I╞-THE╬-ELS┼ statement≤¡-aε illusioε iε whicΦ ì
  61. ì
  62. ááááááááááprograφ speeΣ caε vanisΦ iε ß pufµ oµ smoke« ì
  63.  
  64. áááááááááá     T∩ understanΣ thσ problem¼ let'≤ sa≈ thσ lad∙ iε ì
  65. ì
  66. ááááááááááhalµ¡-exposinτ thσ innard≤ oµ ß simplσ Pasca∞ CAS┼ ìèì
  67. áááááááááástatement«  Then¼ let'≤ looδ a⌠ ß simila≥ prograφ iε ì
  68. ì
  69. ááááááááááassembl∙ language«  Finally¼ let'≤ reassemblσ ou≥ victiφ ì
  70. ì
  71. áááááááááá(volunteer⌐ addinτ fas⌠ jum≡ tablσ CAS┼ statement≤ t∩ ì
  72. ì
  73. ááááááááááTurb∩ Pascal«  A≤ you'l∞ see¼ thσ resul⌠ caε bσ ß ì
  74. ì
  75. áááááááááátremendou≤ boos⌠ iε prograφ speed« ì
  76.  
  77. ááááááááááì
  78.  
  79. ááááááááááì
  80.  
  81. áááááááááá"He∙ Rocky¼ Wannß Seσ Mσ Pul∞ ß Rabbi⌠ Ou⌠ oµ M∙ Hat┐  ì
  82. ì
  83. áááááááááá...Oops¼ Wronτ Hat!ó ì
  84.  
  85. ááááááááááì
  86.  
  87. áááááááááá     Listinτ ▒ illustrate≤ ß typica∞ CAS┼ statemen⌠ iε ì
  88. ì
  89. ááááááááááTurb∩ Pascal«  ┴ FO╥ loo≡ execute≤ thσ CAS┼ statemen⌠ ì
  90. ì
  91. ááááááááááfou≥ times¼ selectinτ amonτ thσ fou≥ labeleΣ statement≤ ì
  92. ì
  93. ááááááááááanΣ callinτ procedure≤ proc0ô througΦ proc3,ô whicΦ ì
  94. ì
  95. áááááááááádispla∙ thσ digit≤ ░-3«  Oµ course¼ thi≤ i≤ ß prett∙ ì
  96. ì
  97. áááááááááádumΓ wa∙ t∩ displa∙ fou≥ digits¼ bu⌠ wσ neeΣ ß voluntee≥ ì
  98. ì
  99. áááááááááát∩ illustratσ thσ inside≤ oµ ß typica∞ CAS┼ statemen⌠ ì
  100. ì
  101. ááááááááááanΣ thi≤ simplσ examplσ suits« ì
  102.  
  103. áááááááááá     Figurσ ▒ disassemble≤ thσ compileΣ CAS┼ statemen⌠ ì
  104. ì
  105. ááááááááááfroφ Listinτ 1«  Thσ firs⌠ MO╓ instructioε load≤ A╪ witΦ ì
  106. ì
  107. ááááááááááthσ valuσ oµ thσ FO╥-loo≡ contro∞ variable¼ i«  Afte≥ ì
  108. ì
  109. ááááááááááthi≤ come≤ thσ codσ fo≥ thσ fou≥ labeleΣ Pasca∞ ì
  110. ì
  111. áááááááááástatements«  EacΦ oµ thesσ statement≤ begin≤ b∙ ì
  112. ì
  113. áááááááááácomparinτ A╪ witΦ thσ label'≤ value¼ 0000¼ 0001¼ 0002¼ ì
  114. ì
  115. ááááááááááo≥ 0003«  Iµ thσ CM╨ fails¼ thσ JN┌ instructioε jump≤ t∩ ì
  116. ì
  117. ááááááááááthσ nex⌠ comparisoε o≥ t∩ thσ enΣ oµ thσ CAS┼ statement«  ì
  118. ìèááááááááááIµ thσ CM╨ doe≤ no⌠ fail¼ theε thσ CAL╠ instructioε ì
  119. ì
  120. áááááááááácall≤ PROC0¼ PROC1¼ PROC2¼ o≥ PROC│¡-thσ assembl∙ ì
  121. ì
  122. áááááááááálanguagσ label≤ fo≥ thσ Pasca∞ procedure≤ oµ thσ samσ ì
  123. ì
  124. áááááááááánames«  Afte≥ thσ CALL¼ ß JM╨ instructioε jump≤ t∩ thσ ì
  125. ì
  126. ááááááááááenΣ oµ thσ CAS┼ statement« ì
  127.  
  128. áááááááááá     Froφ thi≤ analysis¼ eveε iµ you'rσ no⌠ aε assembl∙ ì
  129. ì
  130. áááááááááálanguagσ wizard¼ yo⌡ caε seσ tha⌠ i⌠ take≤ fou≥ CM╨ anΣ ì
  131. ì
  132. ááááááááááJN┌ instructioε pair≤ t∩ cal∞ PROC3¼ threσ sucΦ ì
  133. ì
  134. ááááááááááinstructioε pair≤ t∩ cal∞ PROC2¼ anΣ s∩ on«  Thσ CAS┼ ì
  135. ì
  136. áááááááááástatemen⌠ ma∙ seeφ magicall∙ efficien⌠ iε thσ Pasca∞ ì
  137. ì
  138. áááááááááásourcσ code¼ executinτ labeleΣ statement≤ a⌠ randoφ likσ ì
  139. ì
  140. áááááááááárabbit≤ pulleΣ froφ ß hat«  Bu⌠ it'≤ thσ wronτ hat«  ì
  141. ì
  142. ááááááááááInsteaΣ oµ ß fas⌠ hare¼ iε thσ compileΣ code¼ wσ ge⌠ ß ì
  143. ì
  144. áááááááááátediou≤ I╞-THE╬-ELS┼ tortoise«  AnΣ thi≤ i≤ onl∙ ß ì
  145. ì
  146. áááááááááásimplσ fou≥-labe∞ CAS┼ statement«  Ever∙ additiona∞ ì
  147. ì
  148. áááááááááálabe∞ add≤ anothe≥ CM╨ anΣ JN┌ pair¼ makinτ thσ prograφ ì
  149. ì
  150. ááááááááááworδ harde≥ anΣ harde≥ t∩ reacΦ thσ las⌠ labeleΣ ì
  151. ì
  152. áááááááááástatement« ì
  153.  
  154. ááááááááááì
  155.  
  156. ááááááááááì
  157.  
  158. ááááááááááImprovinτ CAS┼ Statemen⌠ SpeeΣ ì
  159.  
  160. ááááááááááì
  161.  
  162. áááááááááá     Withou⌠ resortinτ t∩ assembl∙ language¼ therσ arσ ß ì
  163. ì
  164. ááááááááááfe≈ prestidigitation≤ yo⌡ caε perforφ t∩ improvσ CAS┼ ì
  165. ì
  166. áááááááááástatemen⌠ speed«  Onσ trick¼ suggesteΣ b∙ Joε Greenblat⌠ ì
  167. ì
  168. ááááááááááiε "┴ Notσ oε Optimizinτ Turb∩ Pascal,ó (P╩ ì
  169. ì
  170. ááááááááááSeptember/Octobe≥ 1987¼ p≡ 4▓-43)¼ i≤ t∩ placσ thσ morσ ìèì
  171. ááááááááááfrequentl∙ useΣ label≤ neare≥ t∩ thσ CAS┼ ke∙ word«  Oµ ì
  172. ì
  173. áááááááááácourse¼ thσ tradeofµ i≤ ß los≤ oµ speeΣ fo≥ thσ labeleΣ ì
  174. ì
  175. áááááááááástatement≤ moveΣ farthe≥ down« ì
  176.  
  177. áááááááááá     Avoidinτ compounΣ statement≤ is anothe≥ gooΣ idea«  ì
  178. ì
  179. ááááááááááFo≥ example¼ conside≥ thi≤ CAS┼ statement║ ì
  180.  
  181. ááááááááááì
  182.  
  183. .ls1
  184. ááááááááááCASE Θ OF
  185. áááááááááá   ░ ║ Proc0;
  186. áááááááááá   ▒ ║ BEGIN
  187. áááááááááá          Writeln¿ 'Firs⌠ lineº );
  188. áááááááááá          Writeln¿ 'Inde° valuσ ╜ '¼ Θ );
  189. áááááááááá          Writeln¿ 'Inde° squareΣ ╜ '¼ Θ ¬ Θ );
  190. áááááááááá          Writeln¿ 'Inde° cubeΣ ╜ '¼ Θ ¬ Θ ¬ Θ )
  191. áááááááááá       END;
  192. áááááááááá   ▓ ║ Proc2
  193. ááááááááááEND;
  194. .ls2
  195. ì
  196.  
  197. ì
  198.  
  199. áááááááááá     Thσ largσ compounΣ statemen⌠ a⌠ labe∞ ▒ prevent≤ ì
  200. ì
  201. ááááááááááTurb∩ Pasca∞ froφ usinτ thσ CMP/JN┌ instructioε pai≥ a≤ ì
  202. ì
  203. ááááááááááiε Figurσ ▒ becausσ JN┌ caε jum≡ onl∙ 12╖ byte≤ forward«  ì
  204. ì
  205. ááááááááááInstead¼ thσ compile≥ generate≤ thσ followinτ codσ t∩ ì
  206. ì
  207. áááááááááájum≡ t∩ thσ statemen⌠ a⌠ labe∞ 2║ ì
  208.  
  209. ááááááááááì
  210.  
  211. .ls1
  212. ááááááááááCM╨ AX,000▒  ╗ I≤ selecto≥ ╜ 1?
  213. ááááááááááJ┌  @+1D     ╗ Yes¼ jum≡ int∩ compounΣ statement
  214. ááááááááááJM╨ @+C╡     ╗ No¼ jum≡ t∩ nex⌠ casσ label
  215. .ls2
  216. ááááááááááì
  217.  
  218. ááááááááááì
  219.  
  220. áááááááááá     Thi≤ arrangemen⌠ require≤ executinτ threσ ì
  221. ì
  222. ááááááááááinstructions¼ CMP¼ JZ¼ anΣ JMP¼ fo≥ eacΦ labe∞ no⌠ ì
  223. ì
  224. áááááááááámatchinτ thσ CAS┼ selector«  Yo⌡ caε avoiΣ thσ ì
  225. ì
  226. ááááááááááadditiona∞ JM╨ b∙ convertinτ thσ compounΣ statemen⌠ int∩ ìèì
  227. ááááááááááß procedure¼ althougΦ thi≤ add≤ thσ overheaΣ associateΣ ì
  228. ì
  229. ááááááááááwitΦ callinτ subroutine≤ plu≤ thσ miscellaneou≤ chore≤ ì
  230. ì
  231. ááááááááááperformeΣ insidσ thσ procedurσ codσ itself«  Eveε so¼ ì
  232. ì
  233. ááááááááááthσ CAS┼ statemen⌠ a≤ ß wholσ operate≤ faste≥ witΦ ì
  234. ì
  235. áááááááááásimplσ labeleΣ statement≤ tha⌠ takσ 12╖ byte≤ o≥ less« ì
  236.  
  237. áááááááááá     BeyonΣ thesσ tw∩ suggestion≤¡-movinτ frequentl∙ ì
  238. ì
  239. ááááááááááuseΣ CAS┼ label≤ a≤ higΦ a≤ possiblσ anΣ avoidinτ ì
  240. ì
  241. áááááááááálargσ compounΣ statement≤¡-therσ isn'⌠ mucΦ yo⌡ caε d∩ ì
  242. ì
  243. áááááááááát∩ improvσ ß CAS┼ statement'≤ performance«  Iµ you'rσ ì
  244. ì
  245. ááááááááááwillinτ t∩ usσ assembl∙ language¼ though¼ witΦ thσ hel≡ ì
  246. ì
  247. ááááááááááoµ ß constructioε calleΣ ß jum≡ table¼ ß littlσ machinσ ì
  248. ì
  249. áááááááááácodσ i≤ likσ pixiσ dus⌠¡-i⌠ caε makσ ß CAS┼ statemen⌠ ì
  250. ì
  251. ááááááááááreall∙ fly« ì
  252.  
  253. ááááááááááì
  254.  
  255. ááááááááááì
  256.  
  257. ááááááááááUnderstandinτ Jum≡ Table≤ ì
  258.  
  259. ááááááááááì
  260.  
  261. áááááááááá     Iµ you'rσ queas∙ abou⌠ assembl∙ language¼ thσ ì
  262. ì
  263. ááááááááááfollowinτ migh⌠ givσ yo⌡ butterflies«  Bea≥ witΦ me«  ì
  264. ì
  265. ááááááááááWe'l∞ returε t∩ Pasca∞ iε ß moment« ì
  266.  
  267. áááááááááá     Listinτ ▓ i≤ ß MAS═ 5.░ examplσ oµ aε assembl∙ ì
  268. ì
  269. áááááááááálanguagσ jum≡ tablσ¡-thσ rougΦ equivalen⌠ oµ thσ Pasca∞ ì
  270. ì
  271. ááááááááááCAS┼ statemen⌠ examplσ iε Listinτ 1«  Thσ tablσ iε thσ ì
  272. ì
  273. áááááááááádatß segmen⌠ store≤ thσ fou≥ offse⌠ addresse≤ oµ thσ ì
  274. ì
  275. áááááááááálabels¼ case0¼ case1¼ case2¼ anΣ case3«  Afte≥ ì
  276. ì
  277. ááááááááááinitializinτ ß fe≈ items¼ thσ prograφ execute≤ thσ codσ ì
  278. ì
  279. ááááááááááa⌠ onσ oµ thesσ labels¼ jumpinτ indirectl∙ t∩ thσ ìèì
  280. ááááááááááappropriatσ addres≤ storeΣ iε thσ table«  Savσ thσ ì
  281. ì
  282. ááááááááááprograφ a≤ CASE.ASM«  Assemblσ anΣ ruε thσ tes⌠ witΦ ì
  283. ì
  284. ááááááááááthesσ DO╙ commands║ ì
  285.  
  286. ááááááááááì
  287.  
  288. .ls1
  289. ááááááááááMAS═ CASE;
  290. ááááááááááLIN╦ CASE;
  291. ááááááááááCASE
  292. .ls2
  293. ááááááááááì
  294.  
  295. ááááááááááì
  296.  
  297. áááááááááá     Typσ 0¼ 1¼ 2¼ o≥ │ t∩ executσ onσ oµ thσ fou≥ ì
  298. ì
  299. áááááááááálabeleΣ cases«  Typinτ anythinτ elsσ end≤ thσ prograφ ì
  300. ì
  301. ááááááááááwitΦ aε erro≥ message«  Examinσ thσ instruction≤ jus⌠ ì
  302. ì
  303. ááááááááááabovσ case0«  Afte≥ gettinτ anΣ testinτ ß keypress¼ thσ ì
  304. ì
  305. ááááááááááprograφ load≤ B╠ witΦ thσ digi⌠ iε AL¼ theε AND≤ thσ ì
  306. ì
  307. ááááááááááresul⌠ witΦ 03¼ creatinτ ß 1╢-bi⌠ valuσ ranginτ froφ ░ ì
  308. ì
  309. áááááááááát∩ 3«  Shiftinτ thi≤ valuσ onσ bi⌠ t∩ thσ lef⌠ ì
  310. ì
  311. áááááááááámultiplie≤ B╪ b∙ 2¼ forminτ ß worΣ inde° int∩ thσ ì
  312. ì
  313. ááááááááááaddres≤ table«  Afte≥ this¼ thσ JM╨ instructioε execute≤ ì
  314. ì
  315. ááááááááááthσ selecteΣ casσ b∙ jumpinτ indirectl∙ t∩ thσ ì
  316. ì
  317. ááááááááááappropriatσ address« ì
  318.  
  319. áááááááááá     Becausσ thσ samσ JM╨ instructioε execute≤ al∞ oµ ì
  320. ì
  321. ááááááááááthσ labeleΣ sections¼ case░ througΦ case3¼ i⌠ take≤ n∩ ì
  322. ì
  323. áááááááááámorσ timσ t∩ star⌠ runninτ thσ codσ a⌠ case│ thaε i⌠ ì
  324. ì
  325. áááááááááádoe≤ t∩ star⌠ thσ codσ a⌠ case0«  EacΦ casσ i≤ giveε ì
  326. ì
  327. ááááááááááequa∞ time¼ ß democratiπ arrangemen⌠ anΣ primar∙ ì
  328. ì
  329. ááááááááááadvantagσ oµ jum≡ tables« ì
  330.  
  331. áááááááááá     Despitσ thi≤ advantage¼ though¼ therσ i≤ onσ maiε ì
  332. ì
  333. áááááááááádisadvantagσ t∩ usinτ jum≡ tables«  Iµ you≥ casσ ìèì
  334. ááááááááááselecto≥ value≤ (thσ digit≤ iε A╠ iε thi≤ example⌐ arσ ì
  335. ì
  336. ááááááááááwidel∙ separated¼ yo⌡ mus⌠ inser⌠ dumm∙ offset≤ int∩ thσ ì
  337. ì
  338. áááááááááátable«  Fo≥ example¼ supposσ you≥ selector≤ arσ 0¼ 2¼ 4¼ ì
  339. ì
  340. ááááááááááanΣ 6«  Thσ jum≡ tablσ mus⌠ reservσ spacσ fo≥ thσ unuseΣ ì
  341. ì
  342. áááááááááávalues¼ 1¼ 3¼ anΣ 5«  Thσ easies⌠ methoΣ i≤ t∩ usσ thσ ì
  343. ì
  344. ááááááááááendcasσ labe∞ fo≥ unuseΣ selecto≥ values¼ rewritinτ thσ ì
  345. ì
  346. áááááááááájum≡ tablσ s∩ tha⌠ thσ illega∞ value≤ 1¼ 3¼ anΣ ╡ simpl∙ ì
  347. ì
  348. áááááááááájum≡ t∩ thσ enΣ oµ thσ casσ selections║ ì
  349.  
  350. ááááááááááì
  351.  
  352. .ls1
  353. áááááááááátablσ d≈ case0¼ endcase¼ case1¼ endcase
  354. áááááááááá      d≈ case2¼ endcase¼ case3
  355. .ls2
  356. ááááááááááì
  357.  
  358. ááááááááááì
  359.  
  360. áááááááááá     WitΦ greatl∙ separateΣ values¼ sa∙ onl∙ ╢ possiblσ ì
  361. ì
  362. áááááááááávalue≤ iε thσ rangσ ░ t∩ 255¼ thσ numbe≥ oµ endcasσ ì
  363. ì
  364. ááááááááááentrie≤ fo≥ unuseΣ value≤ migh⌠ causσ thσ jum≡ tablσ t∩ ì
  365. ì
  366. áááááááááágro≈ to∩ largσ fo≥ you≥ requirements«  Iε thi≤ event¼ ì
  367. ì
  368. ááááááááááyo⌡ mus⌠ conside≥ whethe≥ thσ timσ saving≤ oµ jum≡ ì
  369. ì
  370. áááááááááátable≤ arσ wortΦ thσ wasteΣ memor∙ yo⌡ caε savσ witΦ ß ì
  371. ì
  372. ááááááááááserie≤ oµ conditiona∞ jumps« ì
  373.  
  374. ááááááááááì
  375.  
  376. ááááááááááì
  377.  
  378. ááááááááááWritinτ Jum≡ Table≤ iε Pasca∞ ì
  379.  
  380. ááááááááááì
  381.  
  382. áááááááááá     Okay¼ we'vσ saweΣ thσ lad∙ iε tw∩ anΣ we'vσ seeε ì
  383. ì
  384. ááááááááááwha⌠ she'≤ go⌠ inside«  Wσ kno≈ ho≈ t∩ codσ ß jum≡ tablσ ì
  385. ì
  386. ááááááááááiε assembl∙ language«  We'vσ seeε tha⌠ jum≡ table≤ ì
  387. ìèááááááááááoperatσ morσ efficientl∙ thaε compileΣ Pasca∞ CAS┼ ì
  388. ì
  389. áááááááááástatement≤ b∙ givinτ equa∞ acces≤ t∩ labeleΣ statements«  ì
  390. ì
  391. ááááááááááThσ question≤ remain║ Ho≈ caε wσ teacΦ Turb∩ Pasca∞ t∩ ì
  392. ì
  393. ááááááááááusσ jum≡ tables¼ anΣ wha⌠ arσ thσ practica∞ benefits┐ ì
  394.  
  395. áááááááááá     Listinτ │ illustrate≤ onσ solution¼ thσ functiona∞ ì
  396. ì
  397. ááááááááááequivalen⌠ oµ Listinτ 1«  Thσ globa∞ tableô variablσ ì
  398. ì
  399. ááááááááááhold≤ thσ offse⌠ addresse≤ oµ thσ procedures¼ proc0¼ ì
  400. ì
  401. ááááááááááproc1¼ proc2,ô anΣ proc3«  Thσ firs⌠ fou≥ statement≤ iε ì
  402. ì
  403. ááááááááááthσ maiε prograφ initializσ thi≤ array« ì
  404.  
  405. áááááááááá     Thσ inlinσ procedure¼ jump,ô replace≤ thσ CAS┼ ì
  406. ì
  407. áááááááááástatemen⌠ iε Listinτ 1¼ duplicatinτ thσ actioε oµ thσ ì
  408. ì
  409. ááááááááááassembl∙ languagσ jum≡ tablσ iε Listinτ 2«  Fo≥ ì
  410. ì
  411. ááááááááááreference¼ here'≤ thσ assembl∙ languagσ fo≥ thσ inlinσ ì
  412. ì
  413. áááááááááácode║ ì
  414.  
  415. ááááááááááì
  416.  
  417. .ls1
  418. áááááááááá5┬           PO╨ BX
  419. ááááááááááD▒ E│        SH╠ BX,1
  420. ááááááááááF╞ 9╖ tablσ  CAL╠ table[BX]
  421. .ls2
  422. ááááááááááì
  423.  
  424. ááááááááááì
  425.  
  426. áááááááááá     Thσ inlinσ jumpô procedurσ take≤ ß singlσ worΣ ì
  427. ì
  428. ááááááááááparameter¼ index,ô thσ counterpar⌠ t∩ thσ CAS┼ statemen⌠ ì
  429. ì
  430. ááááááááááselector«  Inlinσ procedure≤ (anΣ functions⌐ operatσ ì
  431. ì
  432. áááááááááásimilarl∙ t∩ assembl∙ languagσ macros«  Wheε Turb∩ ì
  433. ì
  434. ááááááááááPasca∞ compile≤ thσ FO╥ loop¼ i⌠ replace≤ jumpô witΦ thσ ì
  435. ì
  436. ááááááááááinlinσ bytes«  Jus⌠ beforehand¼ thσ compile≥ als∩ ì
  437. ì
  438. áááááááááágenerate≤ codσ t∩ pusΦ an∙ parameter≤ ont∩ thσ stack«  ì
  439.  
  440. áááááááááá     Thσ firs⌠ joΓ fo≥ thσ inlinσ code¼ then¼ i≤ t∩ po≡ ì
  441. ìèááááááááááthσ stackeΣ indexô valuσ int∩ BX«  Then¼ thσ SH╠ ì
  442. ì
  443. ááááááááááinstructioε multiplie≤ B╪ b∙ two¼ forminτ ß 1╢-bi⌠ inde° ì
  444. ì
  445. ááááááááááint∩ thσ jum≡ table«  Finally¼ thσ CAL╠ instructioε ì
  446. ì
  447. áááááááááácall≤ thσ procedurσ a⌠ thσ addres≤ previousl∙ storeΣ iε ì
  448. ì
  449. ááááááááááthσ table«  (Thi≤ examplσ use≤ CAL╠ wherσ Listinτ ▓ use≤ ì
  450. ì
  451. ááááááááááJMP¼ bu⌠ thσ ideß i≤ thσ same.⌐ ì
  452.  
  453. áááááááááá     Listinτ │ doe≤ no⌠ perforφ an∙ rangσ check≤ oε ì
  454. ì
  455. áááááááááávariablσ i«  Iε mos⌠ programs¼ thi≤ i≤ somethinτ you'l∞ ì
  456. ì
  457. ááááááááááwan⌠ t∩ add«  Yo⌡ mus⌠ bσ certaiε neve≥ t∩ usσ indexe≤ ì
  458. ì
  459. ááááááááááoutsidσ oµ thσ jum≡ tablσ range¼ o≥ ß prograφ crasΦ i≤ ì
  460. ì
  461. áááááááááácertain«  ì
  462.  
  463. ááááááááááì
  464.  
  465. ááááááááááì
  466.  
  467. ááááááááááUsinτ Jum≡ Table≤ ì
  468.  
  469. ááááááááááì
  470.  
  471. áááááááááá     Beforσ rushinτ ou⌠ t∩ perforφ you≥ owε jum≡ tablσ ì
  472. ì
  473. áááááááááátricks¼ bσ awarσ tha⌠ thσ tableô oµ offset≤ (Listinτ 3⌐ ì
  474. ì
  475. áááááááááámus⌠ bσ ß globa∞ variablσ storeΣ iε Pascal'≤ datß ì
  476. ì
  477. áááááááááásegment«  Thσ inlinσ jumpô procedurσ assume≤ tha⌠ D╙ ì
  478. ì
  479. ááááááááááaddresse≤ thσ datß segmen⌠ a≤ D╙ normall∙ doe≤ iε Turb∩ ì
  480. ì
  481. ááááááááááPascal«  Declarinτ tableô loca∞ t∩ ß procedurσ o≥ ì
  482. ì
  483. ááááááááááfunctioε wil∞ no⌠ worδ becausσ loca∞ variable≤ arσ ì
  484. ì
  485. áááááááááástoreΣ oε thσ stack¼ no⌠ iε thσ datß segment« ì
  486.  
  487. áááááááááá     Onσ disadvantagσ t∩ thσ jum≡ tablσ solutioε i≤ tha⌠ ì
  488. ì
  489. ááááááááááyo⌡ mus⌠ usσ procedurσ call≤ a≤ showε iε Listinτ 3«  Yo⌡ ì
  490. ì
  491. áááááááááácan'⌠ jum≡ t∩ othe≥ kind≤ oµ labeleΣ statement≤ becausσ ì
  492. ì
  493. ááááááááááOF╙ can'⌠ calculatσ thσ addres≤ oµ ß statemen⌠¡-onl∙ ìèì
  494. ááááááááááprocedures¼ functions¼ anΣ variables«  ì
  495.  
  496. áááááááááá     Arσ thσ advantage≤ wortΦ thσ troublσ oµ usinτ jum≡ ì
  497. ì
  498. áááááááááátable≤ iε Pascal┐  A≤ ß tes⌠ (no⌠ listeΣ here)¼ ╔ ì
  499. ì
  500. ááááááááááextendeΣ Listing≤ ▒ anΣ │ t∩ cal∞ 2▒ procedure≤ insteaΣ ì
  501. ì
  502. ááááááááááoµ 4«  ╔ removeΣ thσ Writelε statement≤ anΣ theε ì
  503. ì
  504. ááááááááááexecuteΣ thσ FO╥ loo≡ iε eacΦ prograφ 50,00░ time≤ oε aε ì
  505. ì
  506. áááááááááá8038╢-baseΣ system«  Listinτ ▒ (witΦ thσ Pasca∞ CAS┼ ì
  507. ì
  508. áááááááááástatement⌐ tooδ 23.7▓ second≤ t∩ run«  Listinτ ▓ ¿witΦ ì
  509. ì
  510. ááááááááááthσ inlinσ jumpô procedure⌐ tooδ 12.3╢ seconds¼ almos⌠ ì
  511. ì
  512. áááááááááátwicσ a≤ fast«  ì
  513.  
  514. áááááááááá     A≤ yo⌡ caε see¼ jum≡ table≤ caε dramaticall∙ ì
  515. ì
  516. ááááááááááimprovσ thσ performancσ oµ Turb∩ Pascal'≤ CAS┼ ì
  517. ì
  518. áááááááááástatement«  Thi≤ isn'⌠ ß tricδ you'l∞ usσ al∞ thσ time¼ ì
  519. ì
  520. áááááááááábu⌠ t∩ squeezσ extrß speeΣ froφ you≥ programs¼ yo⌡ migh⌠ ì
  521. ì
  522. áááááááááátr∙ givinτ you≥ CAS┼ statement≤ ß casσ oµ thσ jumps« ì
  523.  
  524. ááááááááááì
  525.  
  526. áááááááááá                          ##ú ì
  527.  
  528.